package tcc.sglj.action;

import tcc.sglj.util.HibernateUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.ParentPackage;

import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.HibernateException;
import org.hibernate.Query;

import tcc.sglj.dao.*;

import tcc.sglj.model.*;
import tcc.sglj.util.*;

/**
 *
 * @author developer
 */
@ParentPackage(value = "json-default")
public class GridAction {

    private List<UserTe> rows;
    private int total = 0;
    private int page = 1;
    private int records;
   // private String root = "rows";

    @Action(value = "list", results =
    @Result(name = "success", type = "json"))
    public String run() {
        Session session = HibernateUtil.getSession();
        Query query = session.createQuery("from UserTe u");        
        this.setRows((List<UserTe>) query.list());
        this.setRecords(this.getRows().size());
        return "success";
    }

    /**
     * @return the rows
     */
    public List<UserTe> getRows() {
        return rows;
    }

    /**
     * @param rows the rows to set
     */
    public void setRows(List<UserTe> rows) {
        this.rows = rows;
    }

    /**
     * @return the total
     */
    public int getTotal() {
        return total;
    }

    /**
     * @param total the total to set
     */
    public void setTotal(int total) {
        this.total = total;
    }

    /**
     * @return the page
     */
    public int getPage() {
        return page;
    }

    /**
     * @param page the page to set
     */
    public void setPage(int page) {
        this.page = page;
    }

    /**
     * @return the records
     */
    public int getRecords() {
        return records;
    }

    /**
     * @param records the records to set
     */
    public void setRecords(int records) {
        this.records = records;
    }

//    /**
//     * @return the root
//     */
//    public String getRoot() {
//        return root;
//    }
//
//    /**
//     * @param root the root to set
//     */
//    public void setRoot(String root) {
//        this.root = root;
//    }

    
}
